package com.api.shopapi.mapper;

import com.api.shopapi.entity.OrderRefund;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface OrderRefundMapper {

    @Insert("insert into order_refund (OrderRefundCode,OrderBusinessCode,UserCode,TradeNo,RefundNo,CreateTime,Status) values" +
            "(#{orderRefund.OrderRefundCode},#{orderRefund.OrderBusinessCode},#{orderRefund.UserCode},#{orderRefund.TradeNo}," +
            "#{orderRefund.RefundNo},#{orderRefund.CreateTime},#{orderRefund.Status})")
    int insert(@Param("orderRefund") OrderRefund orderRefund);

    @Update("update order_refund set OrderBusinessCode=#{orderRefund.OrderBusinessCode},UserCode=#{orderRefund.UserCode},TradeNo=#{orderRefund.TradeNo}," +
            "RefundNo=#{orderRefund.RefundNo},Status=#{orderRefund.Status} " +
            "where OrderRefundCode=#{orderRefund.OrderRefundCode}")
    int update(@Param("orderRefund") OrderRefund orderRefund);

    @Delete("delete from order_refund where OrderRefundCode=#{orderRefundCode}")
    int delete(@Param("orderRefundCode") String orderRefundCode);

    @Select("select * from order_refund where OrderRefundCode=#{orderRefundCode} limit 1")
    OrderRefund getByOrderRefundCode(@Param("orderRefundCode") String orderRefundCode);

    @Select("select * from order_refund where orderBusinessCode=#{orderBusinessCode} limit 1")
    OrderRefund getByOrderBusinessCode(@Param("orderBusinessCode") String orderBusinessCode);

    @Select("<script>" +
            "select * from order_refund ord left join order_business ob on ord.OrderBusinessCode=ob.OrderBusinessCode where 1=1 " +
            " <if test ='userCode !=null and userCode!=\"\"  '>" +
            "  and ord.UserCode=#{userCode} " +
            " </if>" +
            " <if test ='businessCode !=null and businessCode!=\"\"  '>" +
            "  and ob.BusinessCode=#{businessCode} " +
            " </if>" +
            " <if test ='tradeNo !=null and tradeNo!=\"\"  '>" +
            "  and ord.TradeNo like concat('%',#{tradeNo},'%')  " +
            " </if>" +
            " <if test ='refundNo !=null and refundNo!=\"\"  '>" +
            "  and ord.RefundNo like concat('%',#{refundNo},'%')  " +
            " </if>" +
            " <if test =' status !=-1 '>" +
            "  and Status=#{status}  " +
            " </if>" +
            "</script> ")
    List<OrderRefund> getPageList(@Param("userCode") String userCode,@Param("businessCode") String businessCode,
    @Param("tradeNo") String tradeNo,@Param("refundNo") String refundNo,@Param("status") int status);

}
